var express = require('express');
var path = require('path');
var port = process.env.PORT || 3000;
var app = express();

app.set('views', './views');
app.set('view engine', 'jade');

// jade 默认输出html在一行上，格式化html  https://cnodejs.org/topic/513ef6dc069911196d0c9491
if (app.get('env') === 'development') {
    app.locals.pretty = true;
}

//Express 托管静态文件 http://www.expressjs.com.cn/starter/static-files.html
app.use(express.static(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'bower_components')));

app.listen(port);

console.log('imooc started on port ' + port);

app.get('/', (req, res) => {
    res.render('./pages/index', {
        title: 'index',
        movies:[{
            title:'机械警察1',
            _id:1,
            poster:'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
        },{
            title:'机械警察2',
            _id:2,
            poster:'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
        },{
            title:'机械警察3',
            _id:3,
            poster:'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
        }
        ]
    });
});

app.get('/list', (req, res) => {
    res.render('./pages/list', {
        title: 'list'
    });
});

app.get('/detail', (req, res) => {
    res.render('./pages/detail', {
        title: 'detail'
    });
});

app.get('/admin', (req, res) => {
    res.render('./pages/admin', {
        title: 'admin'
    });
});
